package com.langChain4j.multiagent.controller;

import com.base.api.entity.RestResponse;
import com.langChain4j.multiagent.controller.vo.CreateTaskVo;
import com.langChain4j.multiagent.controller.vo.GetTaskDetailVo;
import com.langChain4j.multiagent.controller.vo.UpdateStatusVo;
import com.langChain4j.api.entity.MultiAgentCollaboration;
import com.langChain4j.multiagent.service.MultiAgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 多智能体协作控制器
 *
 * @author linjun
 */
@RestController
@RequestMapping("/api/v1/collaboration")
@Api(tags = "多智能体协作接口")
public class MultiAgentController {

    @Autowired
    private MultiAgentService multiAgentService;

    @PostMapping("/create")
    @ApiOperation("创建多智能体协作任务")
    public RestResponse<Long> createTask(@Valid @RequestBody CreateTaskVo createTaskVo) {
        Long taskId = multiAgentService.createTask(createTaskVo);
        return RestResponse.<Long>builder().data(taskId).build();
    }

    @GetMapping("/detail")
    @ApiOperation("查询多智能体协作任务详情")
    public RestResponse<MultiAgentCollaboration> getTaskDetail(@Valid GetTaskDetailVo detailVo) {
        MultiAgentCollaboration task = multiAgentService.getTaskById(detailVo.getCollaborationId());
        return RestResponse.<MultiAgentCollaboration>builder().data(task).build();
    }

    @PutMapping("/update-status")
    @ApiOperation("更新多智能体协作任务状态")
    public RestResponse<Boolean> updateStatus(@Valid @RequestBody UpdateStatusVo updateStatusVo) {
        boolean success = multiAgentService.updateStatus(updateStatusVo);
        return RestResponse.<Boolean>builder().data(success).build();
    }

}